package ssi.peeno;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.ArrayList;
import ssi.peeno.ciphers.AsymCipher;
import ssi.peeno.managers.ConfigManager;

public class PeenoServer {
	private static ArrayList<PeenoWorker> workers = new ArrayList<PeenoWorker>();
	private static AsymCipher serverCipher;
	public static void main(String[] args) {
		try {
			ConfigManager.load("conf/config.xml");
			ServerSocket SSocket = new ServerSocket(ConfigManager.getPort());
			serverCipher=new AsymCipher("server");
			serverCipher.loadServerKeys();
			while (true) {
				Socket sck = SSocket.accept();
				PeenoWorker worker = new PeenoWorker(sck);
				ConfigManager.log("NEW THREAD STARTED FOR " + sck.getInetAddress().getHostAddress());
				worker.start();
				workers.add(worker);
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	public static AsymCipher getCipher(){
		return serverCipher;
	}
}
